package com.inst.custom_viewdemo.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by Administrator on 2018/2/1 0001.
 */

public class Canvas1View extends View{
    // 1.创建一个画笔
    private Paint mPaint = new Paint();
    //

    // 2.初始化画笔
    private void initPaint() {
        mPaint.setColor(Color.BLUE);       //设置画笔颜色
        mPaint.setStyle(Paint.Style.FILL);  //设置画笔模式为填充
        mPaint.setStrokeWidth(10f);         //设置画笔宽度为10px
    }

    public Canvas1View(Context context) {
        super(context);
//        initPaint();
    }

    public Canvas1View(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        initPaint();
    }

    public Canvas1View(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        //点的绘制
//        canvas.drawPoint(200, 200, mPaint);    //在坐标(200,200)位置绘制一个点
//        canvas.drawPoints(new float[]{          //绘制一组点，坐标位置由float数组指定
//                200,300,
//                200,400,
//                200,460
//        },mPaint);

        //线的绘制
//        canvas.drawLine(300,300,500,600,mPaint);    // 在坐标(300,300)(500,600)之间绘制一条直线
//        canvas.drawLines(new float[]{               // 绘制一组线 每四数字(两个点的坐标)确定一条线
//                100,200,200,200,
//                100,300,200,300
//        },mPaint);


        // 绘制矩形
//        RectF rectF1 = new RectF(50,50,400,200);
//        canvas.drawRect(rectF1,mPaint);

        //绘制圆角矩形
//        RectF rectF2 = new RectF(100,300,800,600);
//        canvas.drawRoundRect(rectF2,30,30,mPaint);

        //绘制椭圆
        // 第一种
//        RectF rectF = new RectF(100,100,800,400);
//        canvas.drawOval(rectF,mPaint);

        //绘制圆
//        canvas.drawCircle(500,500,400,mPaint);  // 绘制一个圆心坐标在(500,500)，半径为400 的圆。

        //绘制圆弧
        //矩形
//        RectF rectF = new RectF(100,100,600,400);
//        mPaint.setColor(Color.GRAY);
//        canvas.drawRect(rectF,mPaint);
        //圆弧
        //startAngle   开始角度
        //sweepAngle   扫过角度
        // useCenter  是否使用中心
//        mPaint.setColor(Color.BLUE);
//        canvas.drawArc(rectF,0,90,false,mPaint);
//        canvas.drawArc(rectF,0,90,true,mPaint);

        //----------------------------------Paint------------------------------------------------
        //画笔有三种模式
        //STROKE                描边
        // FILL                 填充
        //FILL_AND_STROKE      描边加填充

        Paint paint = new Paint();
        paint.setColor(Color.BLUE);
        paint.setStrokeWidth(40);     //为了实验效果明显，特地设置描边宽度非常大

        // 描边
        paint.setStyle(Paint.Style.STROKE);
        canvas.drawCircle(200,200,100,paint);

        // 填充
        paint.setStyle(Paint.Style.FILL);
        canvas.drawCircle(200,500,100,paint);

        // 描边加填充
        paint.setStyle(Paint.Style.FILL_AND_STROKE);
        canvas.drawCircle(200, 800, 100, paint);
    }
}
